// pages/user/integral/particulars/particulars.js
const config = getApp().globalData.config
const T = getApp().globalData.T
let token = ''
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [],
    page: 1,
    size: 10,
    isLoaded: true,
    originFrom:'',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    token = getApp().globalData.token;
    if (options.from == 'recommend') { // 是从推荐首页-记录查询跳转过来
      this.data.originFrom = 'recommend';
      wx.setNavigationBarTitle({
        title:'悬赏奖励金'
      });
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {
    if (this.data.originFrom == 'recommend') {
      this.getRecommendList();
      return ;
    }
    this.getList();
  },

  getRecommendList() {
    T.req({
      loadTitle: '加载中...',
      url: config.api + 'recommendation/earnings',
      method: 'GET',
      data: {
        token: token,
        page: this.data.page,
        size: this.data.size
      },
      success: (res) => {
        if (res.rowCount === this.data.list.length) {
          T.toast({ id: '#toast', text: '没有更多数据了' })
          this.isLoaded = true;
          return;
        }
        this.setData({
          list: [...this.data.list, ...res.list]
        })
      }
    })
  },

  getList() {
    T.req({
      loadTitle: '加载中...',
      url: config.api + 'point/detail',
      method: 'GET',
      data: {
        token: token,
        page: this.data.page,
        size: this.data.size
      },
      success: (res) => {
        if (res.rowCount === this.data.list.length) {
          T.toast({ id: '#toast', text: '没有更多数据了' })
          this.isLoaded = true;
          return;
        }
        this.setData({
          list: [...this.data.list, ...res.list]
        })
      }
    })
  },

  onReachBottom() {
    if (this.data.isLoaded){
      return 
    }
    this.data.page += 1;
    this.getList();
  }
})